package org.atlantis.grosbeak.castor.defaults;

import java.lang.reflect.Type;

import org.atlantis.grosbeak.castor.Castor;
import org.atlantis.grosbeak.castor.FailToCastException;

@SuppressWarnings("unchecked")
public class StringToEnum implements Castor<String, Enum> {

	public Type getFrom() {
		return String.class;
	}

	public Type getTo() {
		return Enum.class;
	}

	public Enum obverseCast(String src, Class<?> toType)
			throws FailToCastException {
		return Enum.valueOf((Class<Enum>) toType, src);
	}

	public String reverseCast(Enum src, Class<?> toType)
			throws FailToCastException {
		return src.name();
	}
}
